package com.itheima;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/*首先初始化一个List,长度是10，值是0-9。
        然后不断的shuffle，直到前3位出现
        3 1 4

        shuffle 1000,000 次，统计出现的概率*/
public class Probability {
    public static void main(String[] args) {
        List<Integer> num = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            num.add(i);
        }
        int show = 0;
        double sum = 1000000;
        for (int i = 0; i < 1000000; i++) {
            int[] same = new int[3];
            Collections.shuffle(num);
            for (int j = 0; j < same.length; j++) {
                same[j] = num.get(j);
                if(same[0] ==3 && same[1] == 1 && same[2] == 4)
                {
                    show++;
                    System.out.println(num);
                    System.out.println("出现次数为"+show);
                }
            }
        }
        double result = show/sum;
        System.out.println("概率为"+result);
    }
}
